package cn.tedu.csmall.stock.controller;


import cn.tedu.csmall.commons.pojo.stock.dto.StockReduceCountDTO;
import cn.tedu.csmall.commons.restful.JsonResult;
import cn.tedu.csmall.stock.service.IStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "库存模块")
@RequestMapping("/base/stock")
public class StockController {
    @Autowired
    private IStockService stockService;

    // 请求类型POST
    //url  20002/base/stock/reduce/count
    //请求参数 StockReduceCountDTO
    //有参数对象，默认把参数对象放到协议体里面{json}
    //如果想要从协议体中获取该对象，需要一个注解@RequestBody,否则获取不到对应内容(会为null)
    @PostMapping("/reduce/count")
    @ApiOperation("减少商品库存")
    public JsonResult reduceCommodityCount(@RequestBody StockReduceCountDTO stockReduceCountDTO) {
        stockService.reduceStockByCommodityCode(stockReduceCountDTO);
        return JsonResult.ok("减少商品库存完成！");
    }
}
